package jsyf.oa.web.wreport;

import com.alibaba.fastjson.JSONObject;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import jsyf.com.util.BaseUtils;
import jsyf.com.util.FastJsonConvert;
import jsyf.com.util.ResponseUtils;
import jsyf.oa.facade.wreport.WReportCusVisitFacade;

/**
 * Created by Administrator on 2017/12/27 0027.
 */
@Api(value = "客户拜访信息接口", description = "客户拜访信息接口")
@Controller
@RequestMapping("/wreportCusVisit")
public class WReportCusVisitController {
    @Resource
    WReportCusVisitFacade wReportCusVisitFacade;

    @ApiOperation(value = "面访/电访签到", notes = "")
    @ApiImplicitParam(name = "jsonData", value = "{'name':'客户姓名','tel':'客户电话','weChat':'微信号','createUserId':'人员id','arrivalsLongitude':'经度','arrivalsLatitude':'纬度','arrivalsAddress':'地址','visitMode':'0电访；1面访'}", dataType = "String", paramType = "body")
    @RequestMapping(value = "/signIn.json", method = RequestMethod.POST)
    public void signIn(HttpServletResponse response, @RequestBody String jsonData) {
        String id = wReportCusVisitFacade.save(jsonData);
        JSONObject obj = new JSONObject();
        obj.put("id", id);
        ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjRespond(obj));
    }

    @ApiOperation(value = "面访签到app", notes = "")
    @ApiImplicitParam(name = "jsonData", value = "{'name':'客户姓名','tel':'客户电话','weChat':'微信号','createUserId':'人员id','arrivalsLongitude':'经度','arrivalsLatitude':'纬度','arrivalsAddress':'地址','visitMode':'0电访；1面访'}", dataType = "String", paramType = "body")
    @RequestMapping(value = "/faceInApp.json", method = RequestMethod.POST)
    public void faceInApp(HttpServletResponse response, @RequestBody String jsonData) {
        String id = wReportCusVisitFacade.faceInApp(jsonData);
        JSONObject obj = new JSONObject();
        obj.put("id", id);
        ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjRespond(obj));
    }

    @ApiOperation(value = "面访签退", notes = "")
    @ApiImplicitParam(name = "jsonData", value = "{'id':'id','name':'客户姓名','tel':'客户电话','weChat':'微信号','createUserId':'人员id','leaveImg':'签退照片路径','leaveLongitude':'经度','leaveLatitude':'纬度','leaveAddress':'地址','fundCondition':'资金情况'，'existingDevice':'已有设备'，'otherCondition':'其他情况'}", dataType = "String", paramType = "body")
    @RequestMapping(value = "/signOut.json", method = RequestMethod.POST)
    public void signOut(HttpServletResponse response, @RequestBody String jsonData) {
        Integer r = wReportCusVisitFacade.update(jsonData);
        ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjRespond(r.toString()));
    }

    @ApiOperation(value = "面访签退app", notes = "")
    @ApiImplicitParam(name = "jsonData", value = "{'id':'id','name':'客户姓名','tel':'客户电话','weChat':'微信号','createUserId':'" + "人员id','leaveImg':'签退照片路径','leaveLongitude':'经度','leaveLatitude':'纬度','leaveAddress':'地址'，" + "'fundCondition':'资金情况'，'existingDevice':'已有设备'，'otherCondition':'其他情况'}", dataType = "String", paramType = "body")
    @RequestMapping(value = "/faceOutApp.json", method = RequestMethod.POST)
    public void faceOutApp(HttpServletResponse response, @RequestBody String jsonData) {
        String id = wReportCusVisitFacade.faceOutApp(jsonData);
        JSONObject obj = new JSONObject();
        obj.put("id", id);
        ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjRespond(obj));
    }

    @ApiOperation(value = "获取面访人信息", notes = "")
    @ApiImplicitParam(name = "jsonData", value = "{'id':'拜访id'}", dataType = "String", paramType = "body")
    @RequestMapping(value = "/getCustomerVisitById.json", method = RequestMethod.POST)
    public void getCustomerVisitById(HttpServletResponse response, @RequestBody String jsonData) {
        JSONObject jsonParam = FastJsonConvert.convertJSONToObject(jsonData, JSONObject.class);
        JSONObject id = wReportCusVisitFacade.getCustomerVisitById(jsonParam.getString("id"));
        ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjRespond(id));
    }

    @ApiOperation(value = "通过客户手机号获取拜访(0电/1面)最近一条信息", notes = "")
    @ApiImplicitParam(name = "jsonData", value = "{'userId':'当前用户id','visitMode':'0电/1面','tel':'客户手机号'}", dataType = "String", paramType = "body")
    @RequestMapping(value = "/getLatestCustomerVisitByTel.json", method = RequestMethod.POST)
    public void getLatestCustomerVisitByTel(HttpServletResponse response, @RequestBody String jsonData) {
        JSONObject jsonParam = FastJsonConvert.convertJSONToObject(jsonData, JSONObject.class);
        JSONObject id = wReportCusVisitFacade.getLatestCustomerVisitByTel(jsonParam.getString("userId"), jsonParam.getString("visitMode"), jsonParam.getString("tel"));
        ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjRespond(id));
    }


    @ApiOperation(value = "获取面访列表", notes = "")
    @ApiImplicitParam(name = "jsonData", value = "{'userId':'人员id','reportDate':'工作报告日期','visitMode':'电访/面访'}", dataType = "String", paramType = "body")
    @RequestMapping(value = "/getCustomerListById.json", method = RequestMethod.POST)
    public void getCustomerListById(HttpServletResponse response, @RequestBody String jsonData) {
        JSONObject jsonParam = FastJsonConvert.convertJSONToObject(jsonData, JSONObject.class);
        List<JSONObject> result = wReportCusVisitFacade.getCustomerListById(jsonParam.getString("userId"), jsonParam.getString("reportDate"), jsonParam.getString("visitMode"));
        ResponseUtils.putJsonResponse(response, BaseUtils.succsessArrRespond(result));
    }

    @RequestMapping(value = "/removeApp.json", method = RequestMethod.POST)
    public void delById(HttpServletResponse response, @RequestBody String jsonData) {
        String result = this.wReportCusVisitFacade.removeApp(jsonData);
        ResponseUtils.putJsonResponse(response, result);
    }

    @ApiOperation(value = "获取今日陪同拜访", notes = "")
    @ApiImplicitParam(name = "jsonData", value = "{'userId':'人员id','reportDate':'日期'}", dataType = "String", paramType = "body")
    @RequestMapping(value = "/accompaniedVisitCus.json", method = RequestMethod.POST)
    public void accompaniedVisitCus(HttpServletResponse response, @RequestBody String jsonData) {
        JSONObject jsonParam = FastJsonConvert.convertJSONToObject(jsonData, JSONObject.class);
        List<JSONObject> result = wReportCusVisitFacade.accompaniedVisitCus(jsonData);
        ResponseUtils.putJsonResponse(response, BaseUtils.succsessArrRespond(result));
    }

    @ApiOperation(value = "获取今日自己拜访", notes = "")
    @ApiImplicitParam(name = "jsonData", value = "{'userId':'人员id','reportDate':'日期'}", dataType = "String", paramType = "body")
    @RequestMapping(value = "/selfVisitCus.json", method = RequestMethod.POST)
    public void selfVisitCus(HttpServletResponse response, @RequestBody String jsonData) {
        JSONObject jsonParam = FastJsonConvert.convertJSONToObject(jsonData, JSONObject.class);
        List<JSONObject> result = wReportCusVisitFacade.selfVisitCus(jsonData);
        ResponseUtils.putJsonResponse(response, BaseUtils.succsessArrRespond(result));
    }

    @ApiOperation(value = "陪同面访", notes = "")
    @ApiImplicitParam(name = "jsonData", value = "{{'createUserId':'20171217114042709CDE33A09BE1F2FD',entourageId:'2017121711444D4FAA23826069683DAA',leaveImg:'11111',leaveLongitude:'100.82616536',leaveLatitude:'38.84124647',leaveAddress:'1111111111111111111111111111111',otherCondition:'1111111111111111111111111111111111111111111111111111111111111111111111111111111'}}", dataType = "String", paramType = "body")
    @RequestMapping(value = "/accompaniedVisitCusOutApp.json", method = RequestMethod.POST)
    public void accompaniedVisitCusOutApp(HttpServletResponse response, @RequestBody String jsonData) {
        String id = wReportCusVisitFacade.accompaniedVisitCusOutApp(jsonData);
        JSONObject obj = new JSONObject();
        obj.put("id", id);
        ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjRespond(obj));
    }

}
